package com.ruoyi.eqmonitor.controller;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.domain.OptHandleFlowRecord;
import com.ruoyi.eqmonitor.service.IOptHandleFlowRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 处理流程记录
 * @author ruoyi
 * @date 2022-12-05
 */
@RestController
@RequestMapping("/flowRecord")
public class OptHandleFlowRecordController extends BaseController{
    
    @Autowired
    private IOptHandleFlowRecordService optHandleFlowRecordService;

    /**
     * 处理流程记录列表
     */
    @ApiOperation("处理流程记录列表")
    @GetMapping("/list")
    public TableDataInfo<?> list(OptHandleFlowRecord optHandleFlowRecord){
        startPage();
        List<OptHandleFlowRecord> list = optHandleFlowRecordService.selectOptHandleFlowRecordList(optHandleFlowRecord);
        return getDataTable(list);
    }

    /**
     * 处理流程记录详情
     */
    @ApiOperation("处理流程记录详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(optHandleFlowRecordService.selectOptHandleFlowRecordById(id));
    }

    /**
     * 新增处理流程记录
     */
    @ApiOperation("新增处理流程记录")
    @Log(title = "处理流程记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OptHandleFlowRecord optHandleFlowRecord){
    	optHandleFlowRecord.setCreateTime(new Date());
    	optHandleFlowRecord.setCreateBy(SecurityUtils.getUsername());
        return toAjax(optHandleFlowRecordService.save(optHandleFlowRecord));
    }

    /**
     * 修改处理流程记录
     */
    @ApiOperation("修改处理流程记录")
    @PutMapping
    public AjaxResult edit(@RequestBody OptHandleFlowRecord optHandleFlowRecord){
    	optHandleFlowRecord.setUpdateTime(new Date());
    	optHandleFlowRecord.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(optHandleFlowRecordService.updateById(optHandleFlowRecord));
    }

    /**
     * 删除处理流程记录
     */
    @ApiOperation("删除处理流程记录")
    @Log(title = "处理流程记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(optHandleFlowRecordService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出处理流程记录列表
     */
    @ApiOperation("导出处理流程记录列表")
    @Log(title = "处理流程记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OptHandleFlowRecord optHandleFlowRecord){
        List<OptHandleFlowRecord> list = optHandleFlowRecordService.selectOptHandleFlowRecordList(optHandleFlowRecord);
        ExcelUtil<OptHandleFlowRecord> util = new ExcelUtil<OptHandleFlowRecord>(OptHandleFlowRecord.class);
        util.exportExcel(response, list, "处理流程记录数据");
    }
    
}
